/**
 *
 */
package br.unifor.mia.cd.middleware.encrypt.marshalable;

import br.unifor.mia.cd.middleware.arcademis.marshalable.Marshaller;
import br.unifor.mia.cd.middleware.arcademis.marshalable.MarshallerDecorator;

/**
 * Criptografar os campos
 * @author landim
 *
 */
public class EncryptDecorator implements MarshallerDecorator {

	private Marshaller marshaller;

	private static final String STRING_KEY = "CRIPTOGRAFADO";
	private static final Integer INTEGER_KEY = new Integer(123);

	public EncryptDecorator(Marshaller method) {
		marshaller = method;
	}

	/**
	 * @see br.unifor.mia.cd.middleware.arcademis.marshalable.Marshaller#getFieldMarshalValue(java.lang.String, java.lnag.Object)
	 */
	public Object getFieldMarshalValue(String fieldName, Object obj) {
		Object result = marshaller.getFieldMarshalValue(fieldName, obj);

		return result;
	}

	/**
	 * @see br.unifor.mia.cd.middleware.arcademis.marshalable.Marshaller#getFieldUnMarshalValue(java.lang.String, java.lang.Object, java.lang.Object)
	 */
	public Object getFieldUnMarshalValue(String fieldName, Object obj, Object value) {
		Object result = marshaller.getFieldUnMarshalValue(fieldName, obj, value);

		/*if (result instanceof Integer) {
			result = new Integer(((Integer) result).intValue() - INTEGER_KEY.intValue());
		}
		if (result instanceof String) {
			String resultString = ((String) result);
			result = resultString.substring(0, resultString.lastIndexOf(STRING_KEY));
		}*/
		return result;
	}

}
